home *** CD-ROM | disk | FTP | other *** search
/ Floppyshop 2 / Floppyshop - 2.zip / Floppyshop - 2.iso / art&graf.ix / art-0015 / flicker / pentools.c < prev    next >
C/C++ Source or Header  |  1997-04-16  |  6KB  |  410 lines

  1.  
  2. #include "flicker.h"
  3.  
  4. WORD firstx, firsty;
  5. WORD x_0, y_0, x_1, y_1;
  6.  
  7.  
  8. draw()
  9. {
  10. save_undo();
  11. mouse_on = 0;    /* take over cursor handling ourselves, not in check input */
  12.                 /* it's a mess of global variables, but should let us */
  13.                 /* scribble faster! */
  14. for (;;)
  15.     {
  16.     if (mouse_moved)
  17.         {
  18.         wait_out_beam();    /* reduce mouse cursor flicker */
  19.         restore_m();
  20.         plot(mouse_x, mouse_y, ccolor);
  21.         save_m();
  22.         draw_m();
  23.         update_zoom();
  24.         }
  25.     check_input();
  26.     if (!PDN)
  27.         break;
  28.     }
  29. mouse_on = 1;
  30. }
  31.  
  32. drizzle()
  33. {
  34. register int i;
  35. int xybuf[2];
  36. register int wait;
  37.  
  38. /* make time delay twice as long for brushes as points */
  39. if (brush_ix == 0)
  40.     wait = 1;
  41. else
  42.     wait = 2;
  43. save_undo();
  44. mouse_on = 0;
  45. while (PDN)
  46.     {
  47.     polar(FastRand() + i, FastRand()&0x7, xybuf);
  48.     wait_out_beam();    /* reduce mouse cursor flicker */
  49.     restore_m();
  50.     plot(xybuf[0] + mouse_x, xybuf[1] + mouse_y, ccolor);
  51.     save_m();
  52.     draw_m();
  53.     if (zoom_flag)    /* zoom_buf_to_screen takes about 2/60th of a second */
  54.         zbuf_to_screen();
  55.     else
  56.         wait_a_jiffy(wait);
  57.     i++;
  58.     check_input();
  59.     }
  60. mouse_on = 1;
  61. }
  62.  
  63. spray()
  64. {
  65. register int i;
  66. int xybuf[2];
  67.  
  68. save_undo();
  69. hide_mouse();
  70. while (PDN)
  71.     {
  72.     polar(FastRand() + i, FastRand()&0x1f, xybuf);
  73.     plot(xybuf[0] + mouse_x, xybuf[1] + mouse_y, ccolor);
  74.     if (zoom_flag)
  75.         zbuf_to_screen();
  76.     i++;
  77.     check_input();
  78.     }
  79. show_mouse();
  80. maybe_zoom();
  81. }
  82.  
  83. flood()
  84. {
  85. save_undo();
  86. hide_mouse();
  87. floodfill(mouse_x, mouse_y, ccolor);
  88. show_mouse();
  89. update_zoom();
  90. wait_penup();
  91. }
  92.  
  93.  
  94. init_some_tools()
  95. {
  96. save_undo();
  97. undo_to_buf();
  98. firstx = mouse_x;
  99. firsty = mouse_y;
  100. set_solid_line();
  101. hide_mouse();
  102. draw_on_buffer();
  103. putdot(mouse_x, mouse_y, ccolor);
  104. show_mouse();
  105. update_screen();
  106. }
  107.  
  108. uninit_some_tools()
  109. {
  110. if (!zoom_flag)
  111.     {
  112.     hide_mouse();
  113.     buf_to_screen();
  114.     draw_on_screen();
  115.     show_mouse();
  116.     }
  117. }
  118.  
  119. static
  120. first_mouse()
  121. {
  122. line(firstx, firsty, mouse_x, mouse_y);
  123. }
  124.  
  125. static
  126. first_last()
  127. {
  128. line(firstx, firsty, lastx, lasty);
  129. }
  130.  
  131. draw_line()
  132. {
  133. init_some_tools();
  134. for (;;)
  135.     {
  136.     check_input();
  137.     if (!PDN)
  138.         break;
  139.     if (mouse_moved)
  140.         {
  141.         hide_mouse();
  142.         unundo();
  143.         first_mouse();
  144.         show_mouse();
  145.         update_screen();
  146.         }
  147.     }
  148. uninit_some_tools();
  149. }
  150.  
  151. draw_lines()
  152. {
  153. d_poly(0, 0);
  154. }
  155.  
  156. draw_polygon()
  157. {
  158. d_poly(1, filled_flag);
  159. }
  160.  
  161. #define MAXPTS 64
  162.  
  163. d_poly(connected, filled)
  164. WORD connected, filled;
  165. {
  166. WORD points[MAXPTS*2+2];
  167. register WORD count;
  168.  
  169. init_some_tools();
  170. points[2] = points[0] = mouse_x;
  171. points[3] = points[1] = mouse_y;
  172. count = 2;
  173. wait_penup();
  174. for (;;)
  175.     {
  176.     for (;;)
  177.         {
  178.         check_input();
  179.         if (RDN || count >= MAXPTS)
  180.             {
  181.             hide_mouse();
  182.             unundo();
  183.             some_poly(points, count-1, connected, filled);
  184.             show_mouse();
  185.             update_screen();
  186.             uninit_some_tools();
  187.             return;
  188.             }
  189.         if (PJSTDN)
  190.             {
  191.             points[2*count-2] = points[2*count] = mouse_x;
  192.             points[2*count-1] = points[2*count+1] = mouse_y;
  193.             count++;
  194.             }
  195.         if (mouse_moved)
  196.             {
  197.             points[2*count-2] = mouse_x;
  198.             points[2*count-1] = mouse_y;
  199.             hide_mouse();
  200.             unundo();
  201.             some_poly(points, count, connected, filled);
  202.             show_mouse();
  203.             update_screen();
  204.             }
  205.         }
  206.     }
  207. }
  208.  
  209. some_poly(points, count, connected, filled)
  210. register WORD *points;
  211. register WORD count, connected, filled;
  212. {
  213. if (filled)
  214.     polyfill( points, count, ccolor);
  215. else
  216.     {
  217.     if (connected)
  218.         {
  219.         points[2*count] = points[0];
  220.         points[2*count+1] = points[1];
  221.         polyline( points, count+1, ccolor);
  222.         }
  223.     else
  224.         polyline( points, count, ccolor);
  225.     }
  226. }
  227.  
  228. draw_circle()
  229. {
  230. register int radius;
  231.  
  232. init_some_tools();
  233. for (;;)
  234.     {
  235.     check_input();
  236.     if (!PDN)
  237.         break;
  238.     if (mouse_moved)
  239.         {
  240.         radius = calc_distance(mouse_x, mouse_y, firstx, firsty);
  241.         hide_mouse();
  242.         unundo();
  243.         if (filled_flag)
  244.             disk(firstx, firsty, radius, ccolor);
  245.         else
  246.             circle(firstx, firsty, radius, ccolor);
  247.         show_mouse();
  248.         update_screen();
  249.         }
  250.     }
  251. uninit_some_tools();
  252. }
  253.  
  254. rays()
  255. {
  256. init_some_tools();
  257. for (;;)
  258.     {
  259.     set_solid_line();
  260.     while (PDN)
  261.         {
  262.         if (mouse_moved)
  263.             {
  264.             hide_mouse();
  265.             first_mouse();
  266.             show_mouse();
  267.             update_screen();
  268.             }
  269.         check_input();
  270.         }
  271.     hide_mouse();            
  272.     set_xor_line();            /* go into xor mode */
  273.     first_mouse();            /* and leave up xor line and cursor */
  274.     show_mouse();
  275.     update_screen();
  276.     for (;;)
  277.         {
  278.         check_input();
  279.         if (EDN)    /* if button pushed either out of rays, or back to
  280.                         the pendown state */
  281.             {
  282.             hide_mouse();
  283.             set_xor_line();            /* go into xor mode */
  284.             first_last();
  285.             show_mouse();
  286.             update_screen();
  287.             if (PDN)
  288.                 {
  289.                 break;
  290.                 }
  291.             else
  292.                 {
  293.                 uninit_some_tools();
  294.                 return;
  295.                 }
  296.             }
  297.         if (mouse_moved)    /* if moved erase last xor line and put up new one*/
  298.             {
  299.             hide_mouse();    
  300.             set_xor_line();            /* go into xor mode */
  301.             first_last();
  302.             first_mouse();
  303.             show_mouse();
  304.             update_screen();
  305.             }
  306.         }
  307.     }
  308. }
  309.  
  310. swap_d_box()
  311. {
  312. if (firstx > mouse_x)
  313.     {
  314.     x_0 = mouse_x;
  315.     x_1 = firstx;
  316.     }
  317. else
  318.     {
  319.     x_0 = firstx;
  320.     x_1 = mouse_x;
  321.     }
  322. if (firsty > mouse_y)
  323.     {
  324.     y_0 = mouse_y;
  325.     y_1 = firsty;
  326.     }
  327. else
  328.     {
  329.     y_0 = firsty;
  330.     y_1 = mouse_y;
  331.     }
  332. }
  333.  
  334. lines_cursor()
  335. {
  336. hline(mouse_y, 0, XMAX, white);
  337. vline(mouse_x, 0, YMAX, white);
  338. }
  339.  
  340. d_frame()
  341. {
  342. draw_frame(ccolor, x_0, y_0, x_1, y_1);
  343. }
  344.  
  345. d_block()
  346. {
  347. colblock(ccolor, x_0, y_0, x_1, y_1);
  348. }
  349.  
  350. draw_d_box()
  351. {
  352. if (filled_flag)
  353.     d_block();
  354. else
  355.     d_frame();
  356. }
  357.  
  358. draw_box()
  359. {
  360. init_some_tools();
  361. for (;;)
  362.     {
  363.     check_input();
  364.     if (!PDN)
  365.         break;
  366.     if (mouse_moved)
  367.         {
  368.         hide_mouse();
  369.         unundo();
  370.         swap_d_box();
  371.         draw_d_box();
  372.         show_mouse();
  373.         update_screen();
  374.         }
  375.     }
  376. uninit_some_tools();
  377. }
  378.  
  379. update_zoom()
  380. {
  381. if (zoom_flag && mouse_moved)
  382.     {
  383.     zbuf_to_screen();
  384.     }
  385. }
  386.  
  387. see_buffer()
  388. {
  389. if (zoom_flag)
  390.     zbuf_to_screen();
  391. else
  392.     {
  393.     skip_beam();
  394.     buf_to_screen();
  395.     }
  396. }
  397.  
  398. update_screen()
  399. {
  400. if (mouse_moved)
  401.     see_buffer();
  402. }
  403.  
  404. maybe_zoom()
  405. {
  406. if (zoom_flag)
  407.     zbuf_to_screen();
  408. }
  409.  
  410.